package org.hu.controller;

import lombok.extern.slf4j.Slf4j;
import org.hu.entity.dto.DishAddDTO;
import org.hu.entity.dto.DishPageQueryDTO;
import org.hu.entity.pojo.PageBean;
import org.hu.entity.vo.Result;
import org.hu.entity.vo.UpdateDishVO;
import org.hu.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author HYH
 * &#064;date  2020年5月14日 下午4:01:01
 * &#064;Description 关于菜品的controller
 */
@CrossOrigin
@RestController
@Slf4j
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    // 新增一个菜品
    @PostMapping("/add")
    public Result<String> addDish(@RequestBody DishAddDTO dishAddDTO){
        log.info("新增菜品:{}", dishAddDTO);
        dishService.addDish(dishAddDTO);
        return Result.success("新增成功");
    }

    // 删除一个菜品
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteDish(@PathVariable Integer id){
        log.info("删除菜品:{}",id);
        dishService.deleteDish(id);
        return Result.success("删除成功");
    }

    // 修改一个菜品
    @PostMapping("/update")
    public Result<String> updateDish(@RequestBody UpdateDishVO updateDishVO){
        log.info("修改菜品:{}",updateDishVO);
        dishService.updateDish(updateDishVO);
        return Result.success("修改成功");
    }

    // 查看菜品,支持条件查询和分页
    @PostMapping("/list")
    public Result<PageBean> listDish(@RequestBody DishPageQueryDTO dishPageQueryDTO){
        log.info("查询菜品:{}",dishPageQueryDTO);
        PageBean page = dishService.listDish(dishPageQueryDTO);
        return Result.success("查询成功",page);
    }



}
